home *** CD-ROM | disk | FTP | other *** search
- Path: teal.csn.net!not-for-mail
- From: thads@csn.net (Thad Smith)
- Newsgroups: comp.lang.c,comp.os.ms-windows.nt.misc,comp.programming,comp.std.c,comp.unix.aix
- Subject: Re: function pointers
- Date: 31 Jan 1996 22:34:08 -0700
- Organization: T3 Systems
- Message-ID: <sXEExQ9ytBGL084yn@csn.net>
- References: <4eogio$gt0@giga.bga.com> <4eohgr$gt0@giga.bga.com>
- Reply-To: ThadSmith@acm.org
- NNTP-Posting-Host: 199.117.27.22
-
- In article <4eohgr$gt0@giga.bga.com>, makuch@bga.com (Michael Makuch) wrote:
- >In article <4eogio$gt0@giga.bga.com>, makuch@bga.com says...
- >>
- >>The following c code segment compiles and works on
- >>NT MSVC++ and on SVR4 C compiler, but errors out
- >>on AIX with a type mismatch;
- >>
- >>struct foostruct1 * myfoo1();
- >>struct foostruct2 * myfoo2();
- >>void *(*ptr)();
- >>
- >>ptr = myfoo1;
- >>[snip]
- >>ptr = myfoo2;
- >>
- >>I'm passing the function pointer ptr, to a function
- >>which then calls myfoo1, myfoo2, etc., etc. I can think
- >>of several work arounds but I'd rather get the AIX
- >>compiler to accept it. Is there a portable solution to
- >>get the AIX compiler to accept it?
-
- If void* and struct pointers use the same format and are treated
- identically as function return values, you can use the following
- non-portable code:
-
- ptr = (void*(*)()) myfoo1;
-
- That casts myfoo1 to the same type as ptr.
-
- For portable code, rewrite myfoo1() and myfoo2() to return void*, then
- cast them on invocation to appropriate type. That allows the compiler
- to perform any conversion needed between different pointer types.
- Otherwise the code using the pointer doesn't know to handle a struct
- pointer instead of a void*, assuming the representations are
- different.
-
- Thad
-